#ifndef OGREAPP_H
#define OGREAPP_H

#include <QThread>
#include "lib_global.h"
#include "OgreApplication.h"
#include <QDebug>
#include "basicoject.h"
#include "ocamera.h"
#include "OgreSceneManager.h"
#include "QKeyEvent"


class OScene : public BasicObject
{
    Q_OBJECT

    Q_PROPERTY(float aRed READ aRed WRITE setARed)
    Q_PROPERTY(float aGreen READ aGreen WRITE setAGreen)
    Q_PROPERTY(float aBlue READ aBlue WRITE setABlue)

    Q_PROPERTY(QString mainCamId READ mainCamId WRITE setMainCamId)
public:
    explicit OScene(QObject *parent = 0);
    ~OScene();

    float aRed() const {
        return m_Ared;
    }

    float aGreen() const {
        return m_AGreen;
    }

    float aBlue() const {
        return m_ABlue;
    }

    void setARed(float c);
    void setAGreen(float c);
    void setABlue(float c);

    QString mainCamId() const {
        return m_camId;
    }

    void setMainCamId(QString id) {
        m_camId = id;
        if (m_manager != 0) {
            app->setMainCamera(m_manager->getCamera(m_camId.toStdString()));
        }
    }

    void setObjects(QList<QVariant> olst) {
        BasicObject::setObjects(olst);

        foreach (QVariant obj, m_objects) {
            BasicObject* bo = (BasicObject*)(obj.value<QObject* >());
            addObject(bo);
        }
    }

signals:
    void runSig();
    void onFrameRendered(int timeElapsed);
    void onKeyPress(int key);

public slots:
    void run();
    void addObject(BasicObject* obj);
    void setManager(Ogre::SceneManager* manager);
    void stop();
    void pause();
    void resume();
    void onStopped();

private slots:

private:
    OgreApplication* app;
    QThread thread;
    QList<BasicObject*> objectQueue;
    QList<ONode*> nodeQueue;
    QList<Command> cmdQueue;
    Ogre::SceneManager* m_manager;

    float m_Ared;
    float m_AGreen;
    float m_ABlue;

    QString m_camId;
};

#endif // OGREAPP_H
